package cn.onein.edu.tag;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class EduStaticFileUrlOutputTag extends TagSupport {

	private static final long serialVersionUID = -4468240370829273061L;

	private String value;
	
	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public int doStartTag() throws JspException {
		JspWriter out = pageContext.getOut();
		try {
			
			if(value.startsWith("/")){			
				HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
				
				String centextPath = request.getContextPath();
				out.print(centextPath + value);
			}
			else{
				out.print(value); // 页面中显示的内容
			}		
		} catch (IOException e) {
			throw new JspException(e);
		}
		
		return SKIP_BODY; // 不包含主体内容
	}
}
